package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.entity.CommonEntity;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.PageQuery;
import com.ruoyi.common.core.page.PageUtil;
import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.system.domain.SysMaintain;
import com.ruoyi.system.domain.dto.SysUserDTO;
import com.ruoyi.system.service.ISysMaintainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author wux
 * @date 2023/08/01 9:19
 */
@Api(tags = "(运营端) 设备维护")
@RestController
@RequestMapping("/admin/maintain")
public class SysMaintainController {
    @Autowired
    private ISysMaintainService maintainService;

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "新增/编辑维护内容")
    public ResultEntity add(@RequestBody SysMaintain params) {
        maintainService.saveOrUpdate(params);
        return ResultEntity.createSuccess();
    }

    @PostMapping("/del/{id}")
    @ApiOperation(value = "删除维护内容")
    public ResultEntity add(@PathVariable Long id) {
        SysMaintain entity = new SysMaintain();
        entity.setId(id);
        entity.setDelFlag(1);
        maintainService.updateById(entity);
        return ResultEntity.createSuccess();
    }

    @GetMapping("/list")
    @ApiOperation(value = "维护内容列表查询",response = SysMaintain.class)
    public ResultEntity list(PageQuery pageQuery) {
        PageUtil.startPage(pageQuery);
        return ResultEntity.createSuccess(PageUtil.getPageList(maintainService.list(new LambdaQueryWrapper<SysMaintain>()
                .eq(SysMaintain::getDelFlag,0)
                .orderByDesc(CommonEntity::getUpdateTime))));
    }

}
